﻿using System;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;

namespace EasySL.Controls
{
    public class ExCheckBox : CheckBox
    {
        public ExCheckBox()
        {
            this.Loaded += new System.Windows.RoutedEventHandler(ExCheckBox_Loaded);
        }

        void ExCheckBox_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            FrameworkElement element = this;

            while (element != null && !(element is ExDataGrid))
                element = VisualTreeHelper.GetParent(element) as FrameworkElement;

            if (element is ExDataGrid)
            {
                var dg = element as ExDataGrid;

                foreach (ExDataGridColumn c in dg.Columns)
                {
                    if (c != null && object.Equals(c.Header, this.Content) && c is ExDataGridCheckBoxColumn)
                    {
                        dg.AddCheckAll(this);
                    }
                   
                }
                
            }
        }
    }
}
